package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.SubmitOrder;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/findById")
    public Result findById(Integer id) {
        log.info("查询订单信息：{}", id);
        try {
            Result result = new Result();
            result.setFlag(true);
            result.setData(orderService.findById(id));
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
        }
    }

    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody SubmitOrder submitOrder) {
        log.info("提交预约信息：{}", submitOrder);
        try {
            return orderService.submitOrder(submitOrder);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "预约失败");
        }
    }
}
